import Foundation

class MockComponentsRepositoryImp: RepositoryProtocl {
    private let shouldSucceed: Bool
    private let mockComponents: [HomeComponent]
    
    init(shouldSucceed: Bool = true, mockComponents: [HomeComponent] = [
        HomeComponent.banner(title: "hello"),
        HomeComponent.quickEntry(items: [
            QuickEntryItem(title: "转账", iconName: "arrow.left.arrow.right"),
            QuickEntryItem(title: "信用卡", iconName: "creditcard"),
            QuickEntryItem(title: "理财", iconName: "chart.line.uptrend.xyaxis"),
            QuickEntryItem(title: "保险", iconName: "shield")
        ])
    ]) {
        self.shouldSucceed = shouldSucceed
        self.mockComponents = mockComponents
    }
    
    func fetchComponents() async throws -> [HomeComponent] {
        if shouldSucceed {
            return mockComponents
        } else {
            struct MockError: Error {}
            throw MockError()
        }
    }
}